From dbf7e393fb1a348a6a2d2e41dcf0e0da347aaa84 Mon Sep 17 00:00:00 2001 From: Aaron Schulz Date: Wed, 7 Oct 2015 20:44:54 -0700 Subject: [PATCH] Provide a default "max lag" value for LoadBalancer * No MediaWiki site can tolerate unbounded slave lag without editing and account creation and such being broken and unusable * Also fix a few trivial __construct() IDEA errors Change-Id: I95b8b73be2df3b5a87e7adbf53988cfbeb85c260 --- includes/db/loadbalancer/LBFactory.php | 13 +++++++------ includes/db/loadbalancer/LBFactoryMulti.php | 2 ++ includes/db/loadbalancer/LBFactorySimple.php | 2 ++ includes/db/loadbalancer/LoadBalancer.php | 4 +++- 4 files changed, 14 insertions(+), 7 deletions(-) diff --git a/includes/db/loadbalancer/LBFactory.php b/includes/db/loadbalancer/LBFactory.php index a06d826e2c..bad04f9c1f 100644 --- a/includes/db/loadbalancer/LBFactory.php +++ b/includes/db/loadbalancer/LBFactory.php @@ -29,6 +29,13 @@ abstract class LBFactory { /** @var LBFactory */ private static $instance; + /** + * Construct a factory based on a configuration array (typically from $wgLBFactoryConf) + * @param array $conf + */ + public function __construct( array $conf ) { + } + /** * Disables all access to the load balancer, will cause all database access * to throw a DBAccessError @@ -105,12 +112,6 @@ abstract class LBFactory { self::$instance = $instance; } - /** - * Construct a factory based on a configuration array (typically from $wgLBFactoryConf) - * @param array $conf - */ - abstract public function __construct( array $conf ); - /** * Create a new load balancer object. The resulting object will be untracked, * not chronology-protected, and the caller is responsible for cleaning it up. diff --git a/includes/db/loadbalancer/LBFactoryMulti.php b/includes/db/loadbalancer/LBFactoryMulti.php index 6397bcaaf0..2655659b77 100644 --- a/includes/db/loadbalancer/LBFactoryMulti.php +++ b/includes/db/loadbalancer/LBFactoryMulti.php @@ -158,6 +158,8 @@ class LBFactoryMulti extends LBFactory { * @throws MWException */ public function __construct( array $conf ) { + parent::__construct( $conf ); + $this->chronProt = new ChronologyProtector; $this->conf = $conf; $required = array( 'sectionsByDB', 'sectionLoads', 'serverTemplate' ); diff --git a/includes/db/loadbalancer/LBFactorySimple.php b/includes/db/loadbalancer/LBFactorySimple.php index 90c33b0c08..e328727daf 100644 --- a/includes/db/loadbalancer/LBFactorySimple.php +++ b/includes/db/loadbalancer/LBFactorySimple.php @@ -36,6 +36,8 @@ class LBFactorySimple extends LBFactory { private $loadMonitorClass; public function __construct( array $conf ) { + parent::__construct( $conf ); + $this->chronProt = new ChronologyProtector; $this->loadMonitorClass = isset( $conf['loadMonitorClass'] ) ? $conf['loadMonitorClass'] diff --git a/includes/db/loadbalancer/LoadBalancer.php b/includes/db/loadbalancer/LoadBalancer.php index 3350d19ee5..fbc8c8cdd3 100644 --- a/includes/db/loadbalancer/LoadBalancer.php +++ b/includes/db/loadbalancer/LoadBalancer.php @@ -63,6 +63,8 @@ class LoadBalancer { /** @var integer Warn when this many connection are held */ const CONN_HELD_WARN_THRESHOLD = 10; + /** @var integer Default 'max lag' when unspecified */ + const MAX_LAG = 30; /** * @param array $params Array with keys: @@ -155,7 +157,7 @@ class LoadBalancer { * @param float $maxLag Restrict the maximum allowed lag to this many seconds * @return bool|int|string */ - private function getRandomNonLagged( array $loads, $wiki = false, $maxLag = INF ) { + private function getRandomNonLagged( array $loads, $wiki = false, $maxLag = self::MAX_LAG ) { $lags = $this->getLagTimes( $wiki ); # Unset excessively lagged servers -- 2.20.1